﻿Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace Web.UI.WebControls
    <TargetControlType(GetType(Panel))> _
    Public Class ScrollExtender
        Inherits ExtenderControl

        Private _topHiddenField As New HiddenField

        Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
            MyBase.OnInit(e)
            _topHiddenField.ID = ID & "_topHiddenField"
            Controls.Add(_topHiddenField)
        End Sub

        Protected Overrides Function GetScriptReferences() As System.Collections.Generic.IEnumerable(Of System.Web.UI.ScriptReference)
            Dim reference As New ScriptReference()
            reference.Path = Page.ClientScript.GetWebResourceUrl(Me.GetType(), ItvirtuosoContext.RootNamespace & ".scroll.js")
            Return New ScriptReference() {reference}
        End Function

        Protected Overrides Function GetScriptDescriptors(ByVal targetControl As System.Web.UI.Control) As System.Collections.Generic.IEnumerable(Of System.Web.UI.ScriptDescriptor)
            Dim descriptor As New ScriptBehaviorDescriptor(ItvirtuosoContext.RootNamespace & ".ScrollBehavior", targetControl.ClientID)
            descriptor.AddProperty("scrollId", _topHiddenField.ClientID)
            Return New ScriptDescriptor() {descriptor}
        End Function

        Public Sub Reset()
            _topHiddenField.Value = ""
        End Sub
    End Class
End Namespace
